package o;

import android.app.Application;
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.CountDownLatch;

public class fis {
    private static volatile Context ˏ;

    public static void ॱ(Context context) {
        if (ˏ == null) {
            ˏ = context.getApplicationContext();
        }
    }

    public static Context ˎ() {
        if (ˏ == null) {
            synchronized (fis.class) {
                if (ˏ == null) {
                    if (VERSION.SDK_INT < 18 && Looper.myLooper() != Looper.getMainLooper()) {
                        try {
                            final CountDownLatch countDownLatch = new CountDownLatch(1);
                            new Handler(Looper.getMainLooper()).post(new Runnable() {
                                public void run() {
                                    fis.ˏ = fis.ॱ();
                                    countDownLatch.countDown();
                                }
                            });
                            countDownLatch.await();
                            Context context = ˏ;
                            return context;
                        } catch (InterruptedException e) {
                        }
                    }
                    ˏ = ॱ();
                }
            }
        }
        return ˏ;
    }

    private static Context ॱ() {
        try {
            return ((Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication", new Class[0]).invoke(null, new Object[0])).getApplicationContext();
        } catch (Exception e) {
            try {
                return ((Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", new Class[0]).invoke(null, (Object[]) null)).getApplicationContext();
            } catch (Exception e2) {
                return null;
            }
        }
    }
}
